package com.example.demo;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageInfoController {

    private List<MessageInfo> messageInfoList=new ArrayList<>();

    @RequestMapping("/publish")
    public Boolean publish( MessageInfo messageInfo) {
        //验证
        if(!StringUtils.hasLength(messageInfo.getFrom()) || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getSay())){
            return false;
        }
        //publish
        messageInfoList.add(messageInfo);
        return true;
    }

    //getList
    @RequestMapping("/getList")
    public List<MessageInfo> getMessageInfoList() {
        return messageInfoList;
    }
}
